<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
          clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
          clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择结束时间"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="用户类型">
        <el-select @change="handleQuery" v-model="queryParams.queryUser" placeholder="请选择">
          <el-option label="所有" value="1"></el-option>
          <el-option label="销售" value="2"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="分享人昵称" prop="shareNickName" label-width="100">
        <el-input
          v-model="queryParams.shareNickName"
          placeholder="分享人昵称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="帖子板块" prop="type">
        <el-select
          @change="handleQuery"
          v-model="queryParams.type"
          placeholder="选择分类"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in post_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['business:hairTriggerEvent:export']"
        >导出
        </el-button
        >
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <right-toolbar-->
    <!--        v-model:showSearch="showSearch"-->
    <!--        @queryTable="getList"-->
    <!--      ></right-toolbar>-->
    <!--    </el-row>-->

    <el-table
      v-loading="loading"
      :data="hairTriggerEventList"
    >
      <el-table-column label="分享日期" align="center" prop="shareDate"/>
      <el-table-column label="分享人ID" align="center" prop="shareUserId"/>
      <el-table-column label="分享人昵称" align="center" prop="shareNickName"/>
      <el-table-column label="销售主管" align="center" prop="salesNickName"/>
      <el-table-column label="分享板块" align="center" prop="postType">
        <template #default="scope">
          <dict-tag :options="post_type" :value="scope.row.postType" />
        </template>
      </el-table-column>
      <el-table-column label="分享标题" align="center" prop="title"/>
      <el-table-column label="分享页面内容" show-overflow-tooltip align="center" prop="content"/>
      <el-table-column label="点击次数" align="center" prop="clickNum"/>
      <el-table-column label="点击人数" align="center" prop="clickPersonNum"/>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="HairTriggerEvent">
import {
  getPostShareDetail
} from "@/api/system/hairPost";

const {proxy} = getCurrentInstance();
const { post_type} = proxy.useDict("post_type");
const hairTriggerEventList = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([proxy.parseTime(new Date(), "{y}-{m}-{d}") + ' 00:00:00', proxy.parseTime(new Date(), "{y}-{m}-{d}") + ' 23:59:59']);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 15,
    nickName: undefined,
    queryUser: "1",
    salesDirector: undefined,
    eventValue: undefined,
  },
});

const {queryParams, form, rules} = toRefs(data);

/** 查询用户触发事件记录列表 */
function getList() {
  loading.value = true;
  getPostShareDetail(queryParams.value).then((response) => {
    hairTriggerEventList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  queryParams.value = {
    pageNum: 1,
    pageSize: 15,
    userId: null,
    type: null,
    startDate: null,
    endDate: null,
    nickName: null,
    salesDirector: null,
    eventValue: null,
  };
  handleQuery();
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "system/hairPost/exportPostShareDetail",
    {
      ...queryParams.value,
    },
    `accountStatement_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
